package stateAAs.fusions {
	import org.agony2d.gpu.core.ImageAA;
	import org.agony2d.gpu.FusionAA;
	import org.agony2d.gpu.StateAA;
	import org.agony2d.gpu.TingedImageAA;
	import org.agony2d.gpu.UntingedImageAA;
	import org.agony2d.input.KeyboardManager;
	import org.agony2d.notify.AEvent;
	
public class Fusion_StateAA extends StateAA {
  
	/** overwritable... */
	override public function get smoothing() : Boolean {
		return true
	}
	
	/** overwritable... */
	override public function get tinted() : Boolean {
		return true
	}
	
	/** overwrite... */
	override public function get fullTex() : String {
		return "A_32"
	}
	
	/** overwrite... */
	override public function enter() : void {
		var tintImg:TingedImageAA
		
		mImgA = new UntingedImageAA
		this.group.addNode(mImgA)
		mImgA.textureData = FULL_TEX
		mImgA.x = 200
		mImgA.y = 200
		
		{
			mFusionA = new FusionAA
			mFusionA.x = 10
			this.group.addNode(mFusionA)
			
			{
				tintImg = new TingedImageAA
				tintImg.textureData = FULL_TEX
				mFusionA.addNode(tintImg)
				tintImg.x = 190
				tintImg.y = 215
				tintImg.color = 0xdd0000
			}
		}
		
		{
			mFusionB = new FusionAA
			this.group.addNode(mFusionB)
			
			{
				tintImg = new TingedImageAA
				mFusionB.addNode(tintImg)
				tintImg.textureData = FULL_TEX;
				tintImg.x = 210
				tintImg.y = 215
				tintImg.color = 0x0000dd
			}
		}
		KeyboardManager.getInstance().getState().release.addEventListener("Q", onSwap)
		KeyboardManager.getInstance().getState().release.addEventListener("T", onTex)
	}
	
	override public function exit():void {
		KeyboardManager.getInstance().getState().release.removeEventListener("Q", onSwap)
		KeyboardManager.getInstance().getState().release.removeEventListener("T", onTex)
	}
	
	
	private var mImgA:ImageAA
	private var mFusionA:FusionAA, mFusionB:FusionAA
	private var mFusionC:FusionAA, mFusionD:FusionAA
	private var mIndex:int
	
	private function onSwap(e:AEvent):void {
		if (++mIndex == 3) {
			mIndex = 0
		}
		if (mIndex == 0) {
			this.group.addNodeAt(mImgA, 0)
			//trace(mImgA.fusion.getNodeIndex(mImgA))
			mImgA.textureData = (mImgA.textureData == FULL_TEX) ? "half" : FULL_TEX
		}
		else if (mIndex == 1) {
			mFusionA.addNode(mImgA)
			//trace(mImgA.fusion.getNodeIndex(mImgA))
			mImgA.textureData = (mImgA.textureData == FULL_TEX) ? "half" : FULL_TEX
		}
		else if (mIndex == 2) {
			mFusionB.addNode(mImgA)
			//trace(mImgA.fusion.getNodeIndex(mImgA))
			mImgA.textureData = (mImgA.textureData == FULL_TEX) ? "half" : FULL_TEX
		}
		//trace(mImgA.textureData)
	}
	
	private function onTex(e:AEvent):void {
		mImgA.textureData = (mImgA.textureData == FULL_TEX) ? "half" : FULL_TEX
	}
}
}